package net.kleinhenz.norabase.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RedirectServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String extraPath = req.getPathInfo();
		if (extraPath!=null && extraPath.length()>3) {
			char command = extraPath.charAt(1);
			String id = extraPath.substring(3);
			
			if (command=='r')
				resp.sendRedirect("/rune.html?id=" + id);
			else if (command=='b')
				resp.sendRedirect("/battlegroup.html?id=" + id);
			else
				resp.sendRedirect("/editor.html" + id);
		}
	}
}
